﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectOAUser.aspx.cs" Inherits="Meeting.Web.Admin.SelectBase.SelectOAUser" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>选择参会人员</title>
    <script type="text/javascript" src="../../Scripts/jquery-1.8.2.min.js"></script>
    <!--树样式-->
    <link rel="stylesheet" href="../../Css/zTreeStyle/zTreeStyle.css" type="text/css" />
    <link rel="stylesheet" href="../../Css/main.css" type="text/css" />
    <script type="text/javascript" src="../../Scripts/jquery.ztree.core-3.5.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.ztree.excheck-3.5.js"></script>
    <script type="text/javascript" src="../../Scripts/artDialog4.1.6/artDialog.js?skin=blue"></script>
    <script type="text/javascript" src="../../Scripts/artDialog4.1.6/plugins/iframeTools.js"></script>
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/cupertino/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="../../Css/main.css" />
    <script type="text/javascript" src="../../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../Scripts/common.js"></script>
    <script type="text/javascript">
        var selCount = 0;
        var zTree;
        var CategoryId = "";
        //树初始化 
        var setting = { check: { enable: true },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "account",
                    pIdKey: "parent",
                    rootPId: "0"
                }
            }
        };
        function onClick(event, treeId, treeNode) {

        }
        $(function () {
            art.dialog.removeData('result');
            var rolestr = request("RoleId");
            $.ajax({
                type: "POST",
                url: "../SelectBase/SelectOperation.ashx?method=GetOAEmploy&role=" + rolestr,
                dataType: "json",
                success: function (data, textStatus) {
                    //alert(data);
                    zTree = $.fn.zTree.init($("#treeMain"), setting, data);
                    zTree.expandAll(true);
                    zTree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {

                }
            });
        })

        function GetOaUser() {
            //部门树初始化
            var setting = { check: { enable: true },
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "account",
                        pIdKey: "parent",
                        rootPId: "0"
                    }
                },
                callback: { onCheck: OnChange, onClick: onClick }
            };
            var rolestr = "";
            if ($("#chkParty").attr("checked") == "checked") {
                rolestr += "_" + $("#chkParty").val();
            }
            if ($("#chkWord").attr("checked") == "checked") {
                rolestr += "_" + $("#chkWord").val();
            }
            if ($("#chkElse").attr("checked") == "checked") {
                rolestr += "_" + $("#chkElse").val();
            }
            if ($("#chkLead").attr("checked") == "checked") {
                rolestr += "_" + $("#chkLead").val();
            }
            //alert(rolestr);
            if (rolestr.length > 0) rolestr = rolestr.substr(1);
            $.ajax({
                type: "POST",
                url: "SelectOperation.ashx?method=GetOAEmploy&role=" + rolestr,
                dataType: "json",
                success: function (data, textStatus) {
                    //alert(data);
                    zTree = $.fn.zTree.init($("#treeMain"), setting, data);
                    zTree.expandAll(true);
                    zTree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {

                }
            });
        }
        //设置会议主持人
        function SelectHost() {
            if (zTree == null) return;
            var nodes = zTree.getSelectedNodes();
            if (nodes.length < 1) {
                $.messager.alert("提示", '请选择主持人');
                return;
            }
            $("#HostId").val(nodes[0].account);
            $("#Host").val(nodes[0].name);
            $("#RoleId").val(nodes[0].parent);

        }

        //点击选取树节点 
        function onClick(event, treeId, treeNode) {
            //                if (treeNode.checked == true) {
            //                    treeNode.checked = false;
            //                } else {
            //                    treeNode.checked = true;
            //                }
            //                zTree.updateNode(treeNode, true);
            //                OnChange(event, treeId, treeNode);
        }
        //添加选择人员
        function OnChange(event, treeId, treeNode1) {
            nodes = zTree.getChangeCheckedNodes();
            for (var i = 0, l = nodes.length; i < l; i++) {
                nodes[i].checkedOld = nodes[i].checked;
                var treeNode = nodes[i];
                if (treeNode.checked == true) {
                    if (treeNode.nodetype == "user") {
                        insertUl("onChangeNode", treeNode.account, treeNode.name, treeNode.nodetype);
                    }
                } else {
                    if (treeNode.nodetype == "user") {
                        DelById(treeNode.account);
                    }
                }
            }
        }
        var selNodeJson = "";
        function GetCheckNode() {
            var nodes = zTree.getNodes();
            for (n = 0; n < nodes.length; n++) {
                var t = nodes[n];
                if (t.nodetype == "user" && t.checked == true) {

                    selNodeJson += ",{\"EmployeeId\":\"" + t.account + "\",\"EmployeeName\":\"" + t.name + "\",\"Mobile\":\"" + t.mobile + "\",\"RoleId\":\"" + t.parent + "\",\"EmployeeTitle\":\"" + t.title + "\",\"Sort\":10000}";
                }
                GetSubCheckNode(t);
            }
        }
        function GetSubCheckNode(node) {
            if (node == null) return;
            var nodes = node.children;
            if (nodes == undefined) return;
            //alert(nodes.length);
            for (i = 0; i < nodes.length; i++) {
                var t = nodes[i];
                if (t.nodetype == "user" && t.checked == true) {
                    selNodeJson += ",{\"EmployeeId\":\"" + t.account + "\",\"EmployeeName\":\"" + t.name + "\",\"Mobile\":\"" + t.mobile + "\",\"RoleId\":\"" + t.parent + "\",\"EmployeeTitle\":\"" + t.title + "\",\"Sort\":10000}";
                }
                GetSubCheckNode(t);
            }
        }

        function SelectOk() {

            GetCheckNode();
            if (selNodeJson.length > 0) selNodeJson = selNodeJson.substring(1);
            selNodeJson = "[" + selNodeJson + "]";
            //提交 
            art.dialog.data('result', "true");
            art.dialog.data('selNode', selNodeJson);
            art.dialog.close();


        }

    </script>
    <style type="text/css">
        input
        {
            border: 0;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div style="width: 450px; max-height: 350px; min-height: 170px; text-align: left;
            overflow: auto;">
            <ul id="treeMain" class="ztree">
            </ul>
        </div>
        <div style="text-align:right; margin-top:15px;">
            <a id="A1" class="easyui-linkbutton" onclick="SelectOk();">确定</a>
        </div>
    </div>
    </form>
</body>
</html>
